/**
 * 
 */
package com.home.emp.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.home.emp.dao.EmployeeDAO;
import com.home.emp.dvo.Employee;

/**
 * @author xprk339
 *
 */
public class EmployeeDAOImpl extends HibernateDaoSupport implements EmployeeDAO {

	private Map empData = new HashMap();
	/* (non-Javadoc)
	 * @see com.home.emp.dao.EmployeeDAO#getAllEmployees()
	 */
	public EmployeeDAOImpl(){
		Employee emp = null;
		for (int id = 1; id < 10; id++){
			emp = new Employee();
			emp.setEmpId(new Integer(id));
			emp.setEmpName("Name "+ id);
			emp.setEmpAddress("Location #"+id);
			empData.put(emp.getEmpId(), emp);
		}
	}
	public List getAllEmployees() {
		// TODO Auto-generated method stub
		List emps = null;
		Session session = getSession();
		if (session != null ){
			logger.info("Hibernate session exist.");
			Criteria criteria = session.createCriteria(Employee.class);
			emps = criteria.list(); 
			logger.info("Number of elements found are : "+ emps.size());
			return emps;
		}else {
			logger.error("Failed to get access to Hibernate Session.");
		}
		return emps; 
	}

	/* (non-Javadoc)
	 * @see com.home.emp.dao.EmployeeDAO#getEmployee(java.lang.Integer)
	 */
	public Employee getEmployee(Integer empId) {
		// TODO Auto-generated method stub
		return (Employee) getHibernateTemplate().get(Employee.class, empId);
	}
	public void saveEmployee(Employee employee){
		getHibernateTemplate().save(employee);
	}

}
